package com.bothin.experiment4.service.impl;

import com.bothin.experiment4.model.LogistInfo;
import com.bothin.experiment4.service.ILogistInfoservice;
import com.bothin.experiment4.service.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by bothin
 * At 2019/12/19 17:28
 * Description:
 */
@Service
public class LogistInfoserviceImpl extends BaseServiceImpl<LogistInfo> implements ILogistInfoservice {
    @Override
    public LogistInfo findById(Object id) {
        return logistInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<LogistInfo> findAll() {
        return logistInfoMapper.selectAll();
    }

    @Override
    @Transactional
    public void deleteById(Object id) {
        logistInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(LogistInfo logistInfo) {
        logistInfoMapper.updateByPrimaryKeySelective(logistInfo);
    }

    @Override
    @Transactional
    public void insert(LogistInfo logistInfo) {
        logistInfoMapper.insertSelective(logistInfo);
    }

    @Override
    @Transactional
    public int changeLogistStatus(String id, Integer status) {
        LogistInfo logistInfo = new LogistInfo();
        logistInfo.setId(id);
        logistInfo.setLogistStatus(status);
        return logistInfoMapper.updateByPrimaryKeySelective(logistInfo);
    }

    @Override
    public List<LogistInfo> findByKeyword(String key) {
        return logistInfoMapper.findByKeyword("%"+key+"%");
    }

    @Override
    public LogistInfo findByFormId(String formId) {
        List<LogistInfo> logistInfoList = logistInfoMapper.findByFormId(formId);
        if (logistInfoList.size()>0)
            return logistInfoList.get(0);
        return null;
    }
}
